<?php //some ghetto code here

if (!isset($_GET['id'])) {
	//print_r($this->performaInvoices[0]);
	foreach ($this->performaInvoices as $performaInvoice) {
		echo '<br />';
		echo $performaInvoice->id;
		echo ' - ';
		echo $performaInvoice->customer->user->company_name;
	}
	die();
}
?>

<div id="make-invoice">
<?php
	$performaInvoice = $this->performaInvoice;
	echo ($performaInvoice->invoice) ? link_to('Invoice ID: '.$performaInvoice->invoice->id, array('action' => 'invoice', 'id' => $performaInvoice->invoice->id)) : link_to('Make Invoice', array('action' => 'makeInvoice', 'id' => $performaInvoice->id));

?>
</div>
<div id="print-header">
<div id="proforma-id">
<h2>Proforma Invoice</h2>
<?php echo 'Proforma No: ', $performaInvoice->id, '<br />'; ?>
</div>
<h1>Game City</h1>
15C Whalley Close,<br />Kingston 6.

</div>
<div id="performa-customer-info-container">
<div id="performa-info">
Date: <?php echo strftime('%e %B %Y', strtotime($performaInvoice->created_date)); ?><br />
Rep: Mr. A.M.Ishaq<br />
Phone: 422-1353
</div>
<div id="customer">
Customer:<br />
<?php
echo (($performaInvoice->address_to) ? $performaInvoice->address_to : $performaInvoice->customer->user->full_name()),'<br />',
	(!empty($performaInvoice->customer->user->company_name)) ? ucfirst($performaInvoice->customer->user->company_name).',<br />' : '',
	$performaInvoice->customer->user->address();

if ($performaInvoice->attention) { echo '<br />Attention: ', $performaInvoice->customer->user->full_name(); }

?>
</div>
</div>

<div id="order-specificications">
	<div id="order-headings">
		<div class="quantity"><b>Quantity</b></div>
		<div class="price"><b>Total Price</b></div>
		<div class="description"><b>Product Description</b></div>		
	</div>

<?php
	$sub_total = 0.00;
	foreach ($performaInvoice->orderdetails as $order) {
		$quantity = $order->quantity;
		$price = $order->price;
		$mounting_price = $order->mounting_price;
		$isMounting = $mounting_price > -1;
		$sub_total += $quantity * (($isMounting) ? ($mounting_price + $price) : ($price));
		$product = $order->product;
		echo '<div class="order-row">
				<div class="product-row">
					<div class="quantity">',
						$quantity,
					'</div>
					<div class="price">',
						($quantity > 1) ? (number_to_currency($price * $quantity) . '<br />(' . number_to_currency($price) . ' each)') : number_to_currency($price),
					'</div>
					<div class="description"><b>',
						link_to($product->name, array('action' => 'viewProduct', 'id' => $product->id)),'</b><br />',
						$product->description, '<br />Item#: ',
						$product->id, '<br/>Material: ',
						$product->material, '<br />Dimensions: ',
						$product->get_dimensions(),
					'</div>
				</div>
				<div class="mounting-row">
					<div class="price">',
						($isMounting) ? (($quantity > 1) ? (number_to_currency($mounting_price * $quantity) . '<br />(' . number_to_currency($mounting_price) . ' each)') : number_to_currency($mounting_price)) : 'Not requested',
					'</div>
					<div class="description">
						Mounting
					</div>
				</div>
			</div>';
	}
	$grand_total = $sub_total;
	/*
	if (is_numeric($transport_price = ($performaInvoice->transport_price > -1) ? $performaInvoice->transport_price : 'Not requested')) {
		$grand_total += $transport_price;
		$transport_price = number_to_currency($transport_price);
	}
	*/
	if ($transport_price = ($performaInvoice->transport_price > 0) ? $performaInvoice->transport_price : false) {
		$grand_total += $transport_price;
		$transport_price = number_to_currency($transport_price);
	}
	$grand_total -= ($discount_isset = (($discount = $performaInvoice->discount) > -1)) ? $discount : 0.0;
	echo '<div id="totals">
			<div id="sub-total">
				<div class="price">',
					number_to_currency($sub_total),
				'</div>
				<b>Subtotal</b>
			</div>';
			if ($transport_price) {
				echo
				'<div id="transport">
					<div class="price">',
						$transport_price,
					'</div>
					<b>Transport</b>
				</div>';
			}
	if ($discount_isset) {
		echo '<div id="discount">
				<div class="price">-',
					number_to_currency($discount),
				'</div>
				<b>Discount</b>
			</div>';
	}
	echo '<div id="grand-total">
				<div class="price">',
					number_to_currency($grand_total),
				'</div>
				<b>Grand Total</b>
			</div>
		</div>';
	echo '<div id="payment-info">',
			(($deposit = $performaInvoice->deposit) > -1) ? 'Deposit: '.$deposit.'% ('.number_to_currency(($deposit/100)*$grand_total).')' : '', '<br />',
			$performaInvoice->payment_description,'<br />',
			'Delivery time ',$performaInvoice->delivery_time,' weeks<br />',
			'This Quote is valid for one month (till ', strftime('%A %B %e, %Y', strtotime($performaInvoice->created_date .' +1 month')), ')',
		'</div>';
?>
</div>
